#!/bin/bash

help() {
  echo "List all daemon services"
  echo ""
  echo "Usage:"
  echo "  zdaemon list [options]"
  # echo ""
  # echo "Options:"
  # echo "  -f, --follow  Follow logs"
}

core() {
  if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
    help
    exit 0
  fi

  local services=$(daemon_list $@)

  print() {
    local index=$1
    local service_name=$2

    log "    $index $(color::success "$service_name")"
  }

  local services_count=$(daemon_count)
  if [ $services_count -eq 0 ]; then
    log "    (no avaliable services)"
    exit 0
  fi

  log "daemon services: $services_count"
  log ""

  array::each print $services
}

run() {
  core $@
}

run $@
